#include "Lambda.h"
#include "IVisitor.h"

Lambda::Lambda(const argumentsTypePtr& args, const exprTypePtr& body, int nodeId):
    exprType(nodeId),
    _args(args),
    _body(body)
{
}
    
Lambda::~Lambda()
{
    
}
    
QString Lambda::type() const
{
    return "Lambda";
}
    

argumentsTypePtr Lambda::args()
{
    return _args;
}

void Lambda::setArgs(const argumentsTypePtr& args)
{
    _args = args;
}

exprTypePtr Lambda::body()
{
    return _body;
}

void Lambda::setBody(const exprTypePtr& body)
{
    _body = body;
}

    
QString Lambda::toString() const
{
    return QString("Lambda[args=%1, body=%2]").
                arg(_args ? _args->toString():"").
                arg(_body ? _body->toString():"");
}
    
void Lambda::accept(IVisitor* visitor, const SimpleNodePtr& node)
{
    visitor->visitLambda(node.dynamicCast<Lambda>());
}
    
void Lambda::traverse(IVisitor* visitor)
{
    if (_args != NULL)
        _args->accept(visitor, _args);
    if (_body != NULL)
        _body->accept(visitor, _body);
}